﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xinchen.SOA.Client
{
    public class ConfigManager
    {
        private static string _applicationId;
        private static string _applicationKey;
        private static bool _runAsServer;
        public static string ApplicationKey
        {
            get { return ConfigManager._applicationKey; }
        }
        public static string ApplicationId
        {
            get { return ConfigManager._applicationId; }
        }
        public static bool RunAsServer
        {
            get
            {
                return ConfigManager._runAsServer;
            }
        }


        static ConfigManager()
        {
            var section = ConfigurationManager.GetSection("soaClient") as ConfigSection;
            if (section == null)
            {
                throw new KeyNotFoundException("未找到soaClient配置节");
            }
            //_runAsServer = !string.IsNullOrWhiteSpace(section.RunAsServer) && section.RunAsServer != "false";
            _applicationId = section.ApplicationId;
            //_applicationKey = section.ApplicationKey;
            //if (!_runAsServer)
            //{
            //    if (string.IsNullOrWhiteSpace(_applicationId))
            //    {
            //        throw new KeyNotFoundException("soaClient配置节必须配置ApplicationId属性");
            //    }
            //    if (string.IsNullOrWhiteSpace(_applicationKey))
            //    {
            //        throw new KeyNotFoundException("soaClient配置节必须配置ApplicationKey属性");
            //    }
            //}
        }

    }
}
